/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.user;

import com.nus.constant.ConstantRole;
import com.nus.dataaccess.dao.base.BaseEntity;
import com.nus.dataaccess.dao.role.RoleType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author robin.foe
 */

@Entity
@Table(name="USER_ACCOUNT")
public class UserAccount extends BaseEntity{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ID")
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}


    @Column(name="USERNAME")
    private String username;
    public String getUsername() {return username;}
    public void setUsername(String username) {this.username = username;}


    @Column(name="PASSWORD")
    private String password;
    public String getPassword() {return password;}
    public void setPassword(String password) {this.password = password;}

    @Column(name="THEME", length=100)
    private String theme;
    public String getTheme() {return theme;}
    public void setTheme(String theme) {this.theme = theme;}
    
    @Column(name="ROLE", length=1, columnDefinition="CHAR(1)")
    private String role = ConstantRole.PARTICIPANTS;
    public String getRole() {return role;}
    public void setRole(String role) {this.role = role;}
    
    
    @Transient
    private String transientPassword;
    public String getTransientPassword() {return transientPassword;}
    public void setTransientPassword(String password) {this.transientPassword = password;}

    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(name = "USERACCOUNT_ROLE", joinColumns = { @JoinColumn(name="USER_ACCOUNT_ID") }, inverseJoinColumns = {@JoinColumn(name="ROLE_TYPE_ID")})
    private List<RoleType> roleTypes = new ArrayList<RoleType>();
    public List<RoleType> getRoleTypes() {return roleTypes;}
    public void setRoleTypes(List<RoleType> roleTypes) {
        this.roleTypes = roleTypes;
    }
    public RoleType addNewRoleType() {
        RoleType roleType = new RoleType();
        roleTypes.add(roleType);
        return roleType;
    }
    public void removeDiscipline(RoleType roleType){this.roleTypes.remove(roleType);}

    @OneToOne(mappedBy="userAccount")
    private UserInfo userInfo;
    public UserInfo getUserInfo() {return userInfo;}
    public void setUserInfo(UserInfo userInfo) {this.userInfo = userInfo;}

}
